<%@ page session="true" %>
<%@ page pageEncoding="utf-8" %>
<%@ page contentType="text/html; charset=utf-8"  %>
<%@ page import="java.util.HashMap" %>
<%@ page import="java.util.Vector" %>
<%@ page import="java.util.ResourceBundle" %>
<%@ page import="java.util.MissingResourceException" %>
<%@ page import="java.util.Locale" %>
<%@ page import="java.util.Calendar" %>
<%@ page import="java.text.SimpleDateFormat" %>
<%@ page import="net.canadensys.dataportal.vascan.Taxon" %>
<%@ page import="net.canadensys.dataportal.utils.*" %>
<%@ page import="org.apache.commons.collections.Predicate" %>
<%@ page import="net.canadensys.dataportal.vascan.config.ApplicationConfig" %>
<%@ page import="net.canadensys.dataportal.vascan.config.impl.InstallationConfig" %>
<%@ page import="net.canadensys.dataportal.vascan.config.ConfigManager" %>
<%!
// Copyright (c) 2010 Canadensys
public void notFound(HttpServletResponse response) {
    try{
        response.sendError(HttpServletResponse.SC_NOT_FOUND);
    }
    catch(Exception e){}
}

public void redirect(HttpServletResponse response, String url) {
    response.setStatus(HttpServletResponse.SC_MOVED_PERMANENTLY);
    response.setHeader("Location", url);
}

%>
<%
long now = System.currentTimeMillis();
response.setDateHeader("Expires", now + 7200000);
response.addHeader("Cache-Control","max-age=7200");

String _language = "en";
if(request.getParameter("lang") != null && request.getParameter("lang") != "")
_language = request.getParameter("lang");

SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
String lastPublicationDate = null;
try{
	org.hibernate.Session hibernateLookupSession = HibernateUtil.getSessionFactory().getCurrentSession();
	hibernateLookupSession.beginTransaction();
	lastPublicationDate = ConfigManager.loadValueFromDB(ApplicationConfig.CONFIG_KEY_LAST_PUBLICATION_DATE);
	hibernateLookupSession.getTransaction().commit();
}
catch(Exception ex){
	lastPublicationDate = "?";
}

String _pageUri = request.getRequestURI();
String _pageQuery = request.getQueryString();
String _pageUrl = _pageUri + ((_pageQuery != null) ? "?" + _pageQuery : "");

/* page extra info */
HashMap<String,Object> _page = new HashMap<String,Object>();
_page.put("date",sdf.format(Calendar.getInstance().getTime()));
_page.put("rank",null);
_page.put("isVernacular",null);
_page.put("isSynonym",null);
_page.put("isDisambiguation",null);
_page.put("lastPublicationDate", lastPublicationDate);

if(InstallationConfig.getInstance().get(InstallationConfig.GA_ACCOUNT_KEY) != null && InstallationConfig.getInstance().get(InstallationConfig.GA_SITE_VERIFICATION_KEY) != null){
	_page.put("GAAccount", InstallationConfig.getInstance().get(InstallationConfig.GA_ACCOUNT_KEY));
	_page.put("GASiteVerification", InstallationConfig.getInstance().get(InstallationConfig.GA_SITE_VERIFICATION_KEY));
}

/* language files */
ResourceBundle _bundle;
try{
    _bundle = ResourceBundle.getBundle("vascan", new Locale(_language));
}catch(MissingResourceException e){
    _bundle = ResourceBundle.getBundle("vascan", new Locale("en"));
}


String _error = "";
%>